package com.example.demo.carmanage.controller;

import com.example.demo.carmanage.service.CarService;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Transactional
@CrossOrigin
public class CarController {

    private Logger log = Logger.getLogger(CarController.class);

    @Autowired
    private CarService carService;

    /**
         * @Description 根据条件查询所有车辆信息
         * @Author zhangxue
         * @Date 17:34 2018/7/11
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/queryAllCars",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryAllCars(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = carService.queryAllCars(param);
        return statusMap;
    }

    /**
     * @Description 查询车牌号下拉
     * @Author zhangxue
     * @Date 8:53 2018/6/3
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllCarNo")
    @ResponseBody
    public String queryAllCarNo(){
        JSONObject js= new JSONObject();
        Map<String,Object> resultMap = new HashMap<String, Object>();
        Map<String,Object> param = new HashMap<String, Object>();
        List<Map<String,Object>> resultList = carService.queryAllCarNo(param);
        resultMap.put("data",resultList);
        js = JSONObject.fromObject(resultMap);
        return js.toString();
    }

    /**
         * @Description 新增车辆信息
         * @Author zhangxue
         * @Date 11:18 2018/7/12
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/saveCar",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> saveSHInfo(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = carService.saveCar(param);
        return statusMap;
    }

    /**
         * @Description 删除车辆信息
         * @Author zhangxue
         * @Date 14:30 2018/7/13
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/delCar",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> delSHInfo(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = carService.delCar(param);
        return statusMap;
    }

    /**
         * @Description 修改车辆信息
         * @Author zhangxue
         * @Date 17:48 2018/7/13
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/editCar",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> editCar(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = carService.editCar(param);
        return statusMap;
    }

    /**
         * @Description 查看车辆详情
         * @Author zhangxue
         * @Date 16:16 2018/7/13
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/initCarInfo",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> initCarInfo(@RequestBody Map<String,Object> param){
        Map<String,Object> resultMap = carService.initCarInfo(param);
        return resultMap;
    }

    /**
         * @Description 添加授权书资料路径
         * @Author zhangxue
         * @Date 11:37 2018/7/13
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/uploadBook",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> uploadBook(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = carService.saveUploadBook(param);
        return statusMap;
    }

    /**
     * @Description 添加执照路径
     * @Author zhangxue
     * @Date 11:37 2018/7/13
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/uploadLicense",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> uploadLicense(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = carService.saveUploadLicense(param);
        return statusMap;
    }

    /**
         * @Description 添加身份证照片
         * @Author zhangxue
         * @Date 17:06 2018/7/16
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/uploadCard",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> uploadCard(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = carService.saveUploadCard(param);
        return statusMap;
    }

    /**
         * @Description 新增展位信息
         * @Author zhangxue
         * @Date 15:09 2018/7/13
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/saveZWInfo",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> saveZWInfo(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = carService.saveZWInfo(param);
        return statusMap;
    }

    /**
         * @Description 删除展位信息
         * @Author zhangxue
         * @Date 17:00 2018/7/13
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/delZWInfo",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> delZWInfo(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = carService.delZWInfo(param);
        return statusMap;
    }
}
